class LoadingUI extends UIBase {
    private img_bg:eui.Image;
    private img_spt9:eui.Image;
    public constructor() {
        super('MainLoadingView');
    }

    private progress:eui.Image;
    private lb_tips:eui.Label;

    private originalWidth;

    public init()
    {
        this.resize();
        this.fixIphoneX();
        this.originalWidth = 482;   

        // this.setDate();
    }

    public setDate()
    {
        if(TimeUtil.getIsNight())
        {
            this.img_bg.source = 'bg2_png';
            this.img_spt9.source = 'spt9_bg_di_2_png';
        }
        else
        {
            this.img_bg.source = 'bg_jpg';
            this.img_spt9.source = 'spt9_bg_di_png';
        }
    }

    public onProgress(current: number, total: number, name:string): void {
        let percent;
        let Name = name == 'game' ? '美术资源':'配置文件';
        if(current < total)
        {
            percent = ((current / total) * 100 ).toFixed(0);
            this.lb_tips.text = `正在加载${Name}..${percent}%`;
        }
        else
        {
            this.lb_tips.text = 'wait...'; 
            percent = 100;
        }
        this.progress.width = this.originalWidth * (percent / 100);
    }

    public clear()
    {
        super.clear();
    }
}
